﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Data.SqlClient;

namespace thinger.ADONETTeach
{
    public class CRUDAdvance
    {
        public void Insert1()
        {
            //定义sql语句
            string sql = "insert into Employee(EployName, Gender, NowAddress, IdNo,WeiXinNumber,PhoneNumber, OtherWork, EntryDate, PostId, DepartmentId) values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')";
            //获取用户输入
            Console.WriteLine("请输入员工姓名：");
            string EployName = Console.ReadLine();
            Console.WriteLine("请输入员工性别：");
            string gender = Console.ReadLine();
            Console.WriteLine("请输入员工现在住址：");
            string NowAddress = Console.ReadLine();
            Console.WriteLine("请输入员工身份证号码：");
            string IdNo = Console.ReadLine();
            Console.WriteLine("请输入员工微信号码：");
            string WeiXinNumber = Console.ReadLine();
            Console.WriteLine("请输入员工电话号码：");
            string NPhoneNumber = Console.ReadLine();
            Console.WriteLine("请输入员工其他工作：");
            string OtherWork = Console.ReadLine();
            Console.WriteLine("请输入员工入职日期：");
            string EntryDate = Console.ReadLine();
            Console.WriteLine("请输入员工职位编号：");
            int PostId = int.Parse(Console.ReadLine());
            Console.WriteLine("请输入员工部门编号：");
            int DepartmentId = int.Parse(Console.ReadLine());

            //替换占位符
            sql = string.Format(sql, EployName, gender, NowAddress, IdNo, WeiXinNumber, NPhoneNumber, OtherWork, EntryDate, PostId, DepartmentId);
            //调用通用类
            int result = SQLHelperBase.ExecuteNonQuery(sql);
            Console.WriteLine("受影响的行数:" +result);
        }
        public void Insert2()
        {
            
            #region 获取用户输入(界面中、窗体、网页)
            Console.Write("请输入员工姓名：");
            string EployName = Console.ReadLine();
            Console.Write("请输入员工性别：");
            string gender = Console.ReadLine();
            Console.Write("请输入员工现在住址：");
            string NowAddress = Console.ReadLine();
            Console.Write("请输入员工身份证号码：");
            string IdNo = Console.ReadLine();
            Console.Write("请输入员工微信号码：");
            string WeiXinNumber = Console.ReadLine();
            Console.Write("请输入员工电话号码：");
            string PhoneNumber = Console.ReadLine();
            Console.Write("请输入员工其他工作：");
            string OtherWork = Console.ReadLine();
            Console.Write("请输入员工入职日期：");
            string EntryDate = Console.ReadLine();
            Console.Write("请输入员工职位编号：");
            int PostId = int.Parse(Console.ReadLine());
            Console.Write("请输入员工部门编号：");
            int DepartmentId = int.Parse(Console.ReadLine());
            #endregion

            #region 数据操作
            //定义sql语句
            string sql = "insert into Employee(EployName, Gender, NowAddress, IdNo,WeiXinNumber,PhoneNumber, OtherWork, EntryDate, PostId, DepartmentId)";
            sql += " values(@EployName, @Gender, @NowAddress, @IdNo, @WeiXinNumber, @PhoneNumber, @OtherWork, @EntryDate, @PostId, @DepartmentId)";

            
            //封装参数
            SqlParameter[] param = new SqlParameter[]
            {
                new SqlParameter( "@EployName", EployName ),
                new SqlParameter( "@gender", gender ),
                new SqlParameter( "@NowAddress", NowAddress ),
                new SqlParameter( "@IdNo", IdNo ),
                new SqlParameter( "@WeiXinNumber", WeiXinNumber ),
                 new SqlParameter( "@PhoneNumber", PhoneNumber ),
                new SqlParameter( "@OtherWork", OtherWork ),
                new SqlParameter( "@EntryDate", EntryDate ),
                new SqlParameter( "@PostId", PostId ),
                new SqlParameter( "@DepartmentId", DepartmentId ),
            };
            //调用通用类
            int result = SQLHelperBase.ExecuteNonQuery(sql, param);
            #endregion

            Console.WriteLine("受影响的行数:" + result);
        }
    }
}
